// 简单解法
/*
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int left = nums.size() - 1, right = left;
        while (left >= 0 && left <= right) {
            if (nums[left] == 0) {
                for (int i = left; i < right; i++) {
                    swap(nums[i], nums[i + 1]);
                }
                right--;
            }
            left--;
        }
    }
};
*/

// 双指针一次遍历
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int left = -1, right;
        for (right = 0; right < nums.size(); right++) {
            if (nums[right] == 0) {
                if (left == -1) left = right;
            }
            else {
                if (left != -1) {
                    swap(nums[left], nums[right]);
                    left++;
                }
            }
        }
    }
};